package com.changgou.business.listener;

import javafx.util.Builder;
import okhttp3.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class AdListener {

	//定义监听方法，监听MQ队列
	@RabbitListener(queues = "ad_update_queue")
	public void receiveMessage(String message){
		//打印消息
		System.out.println("MQ监听类监听到的方法是："+message);

		//发送消息到nginx
		OkHttpClient okHttpClient=new OkHttpClient();
		String url="http://192.168.200.128/ad_update?position="+message;
		Request request=new Request.Builder().url(url).build();
		Call call = okHttpClient.newCall(request);

		//发送消息到nginx的回调
		call.enqueue(new Callback() {
			@Override
			public void onFailure(Call call, IOException e) {
				//没有接受到回调
				e.printStackTrace();
			}

			@Override
			public void onResponse(Call call, Response response) throws IOException {
				System.out.println("nginx接受到消息："+response.message());
			}
		});
	}
}
